﻿Imports System.IO
Imports DAO
Imports DTO

Public Class DangNhapBUS

    Shared Sub ghiNhoMatKhau(userName As String, pass As String)
        If File.Exists("MatKhau.txt") = False Then
            File.AppendAllText("MatKhau.txt", userName + "-" + pass)
        Else
            Dim line As String
            Using reader As StreamReader = New StreamReader("MatKhau.txt")
                line = reader.ReadLine
                Do While (Not line Is Nothing)
                    If line = userName + "-" + pass Then
                        Return
                    End If
                    line = reader.ReadLine
                Loop
            End Using
            File.AppendAllText("MatKhau.txt", Environment.NewLine + userName + "-" + pass)
        End If
    End Sub

    Shared Function DangNhap(taiKhoang As String, matKhau As String) As String
        Return DangNhapDAO.DangNhap(taiKhoang, matKhau)
    End Function

    Shared Function docDsTaiKhoanDaLuu() As List(Of NguoiDungDTO)
        Dim dstaiKhoan As New List(Of NguoiDungDTO)
        Dim line As String
        If File.Exists("MatKhau.txt") Then
            Using reader As StreamReader = New StreamReader("MatKhau.txt")
                line = reader.ReadLine
                Do While (Not line Is Nothing)
                    Dim nd As New NguoiDungDTO
                    nd.TaiKhoan = line.Split("-")(0)
                    nd.MatKhau = line.Split("-")(1)
                    dstaiKhoan.Add(nd)
                    line = reader.ReadLine
                Loop
            End Using
        End If
        Return dstaiKhoan
    End Function

End Class
